<% content_for :main_content do %>
<div class="row">
    <div class="col-lg-4">
      <section class="panel">
        <header class="panel-heading">
           主页设置
        </header>
        <div class="panel-body">
          <%= simple_form_for [:merchant, @portal_style], :defaults => { :input_html => { :class => "form-control" } }, html: { multipart: true, remote: true, class: 'form-horizontal tasi-form', id: "portal_config_form" } do |f| %>

              <%= f.input :name, label: "简称" %>
              <!--
              <%= f.input :btn_style %>
              -->
              <div class="form-group">
                <%= f.label "广告" %>
                <div class="col-sm-8">
                  <%= link_to "设置", merchant_banners_path(portal_style_id: @portal_style.id), class: "btn btn-primary" %>
                </div>
              </div>
          <% end %>

        </div>
      </section>

      <% if @deleted_mboxes.present? %>
      <section class="panel">
          <header class="panel-heading">
              未启用模块
          </header>
          <div class="panel-body">
            <div class="simple_form form-horizontal tasi-form">
            <% @deleted_mboxes.each do |box| %>
              <div class="form-group">
                <label class="string optional col-sm-4 col-sm-4 control-label"><%= box.name %></label>
                <div class="col-sm-8">
                    <%= link_to "设置", edit_merchant_mbox_path(box.id), class: "btn btn-primary" %>
                    <%= link_to "启用", enable_merchant_mbox_path(box.id), :method => :post, remote: true, class: "btn btn-primary" %>
                </div>
              </div>
            <% end %>
            </div>
          </div>
      </section>
      <% end %>

    </div>
    <div class="col-lg-4">
      <section class="panel">
      <header class="panel-heading">
         <%= link_to "预览", wifi_merchant_path(mid: @default_terminal.mid), :target => "_blank" %>
      </header>
      <div class="panel-body">
          <!-- config start -->
          <div class="row">
            <div class="col-lg-12 col-xs-12 col-centered">
              <div class="row span5 col-centered shop_title">
                <h5 class="text-center"><strong><span id="portal_style_conf_name"><%= @portal_style.name %></span></strong></h5>
              </div>
              <div class="span5 about-carousel" style="margin-bottom:-15px;">
                <div id="myCarousel" class="carousel slide">
                    <!-- Carousel items -->
                    <div class="carousel-inner">
                    <% if @banners.present? %>
                      <% @banners.each_with_index do |banner,bindex| %>
                          <div class="<%= 'active' if bindex == 0 %> item">
                            <%= image_tag banner.cover %>
                            <div class="carousel-caption">
                                <p><%= banner.description %></p>
                            </div>
                        </div>
                      <% end %>
                    <% else %>
                        <div class="active item">
                            <%= image_tag "about_1.jpg" %>
                            <div class="carousel-caption">
                                <p>Donec luctus ullamcorper nulla</p>
                            </div>
                        </div>
                        <div class="item">
                            <%= image_tag "about_2.jpg" %>
                            <div class="carousel-caption">
                                <p>Blanditiis praesentium voluptatum</p>
                            </div>
                        </div>
                        <div class="item">
                            <%= image_tag "about_1.jpg" %>
                            <div class="carousel-caption">
                                <p>Honest and amazing things that bring positive results</p>
                            </div>
                        </div>
                    <% end %>
                    </div>
                    <!-- Carousel nav -->
                    <a class="carousel-control left" href="#myCarousel" data-slide="prev">
                      <%= fa_icon "angle-left" %>
                    </a>
                    <a class="carousel-control right" href="#myCarousel" data-slide="next">
                      <%= fa_icon "angle-right" %>
                    </a>
                </div>
              </div>
              <div class="row span5 col-centered free-wifi">
                <h4 class="text-center"><%= image_tag 'tu_01_03.png',height: '23' %>点击免费上网</h4>
              </div>
              <!-- portal images start -->
              <div class="portal_images">
              <div class="row span5 col-centered">
                <ul class="dragsortBox" id="list1">
                  <% @mboxes.each do |mbox| %>
                    <li appid="<%=mbox.id%>">
                      <div class="col-lg-6 col-xs-6 thumbnail">
                        <section>
                          <div class="mf-box">
                            <%= image_tag mbox.default_cover %>
                            <h5><%= mbox.name %></h5>
                          </div>
                        </section>
                        <div class="caption">
                          <a class="icon-remove" href="javascript:enable(<%=mbox.id%>,false);"><%= fa_icon("times 2x") %></a>
                          <br />
                          <%= link_to "设置", edit_merchant_mbox_path(mbox.id), class: "btn btn-primary col-centered" %>
                          <p>可鼠标拖动模块进行排序</p>
                          <p>也可以删除此模块</p>
                        </div>
                      </div>
                    </li>
                  <% end %>
                </ul>
              </div>
              </div>
              <!-- portal images end -->
          </div>
        </div>
        <!-- config end -->
      </div>
      </section>
    </div>
</div>
<% end %>

<% content_for :script do %>
  <script type="text/javascript">
    window._token = '<%= form_authenticity_token %>'
    // var i_max = 8;
    // function add_mk(){
    //    dialog=art.dialog({
    //     title: '',
    //       content: document.getElementById('add_mk'),
    //     lock: true
    //   });
    // }//添加模块
    // function zdy_mk(){
    //    dialog=art.dialog({
    //     title: '',
    //       content: document.getElementById('zdy_mk'),
    //     lock: true
    //   });
    // }
    //删除自定义模块
    function enable(appId,isEnable){
      // if(isEnable && 5>=i_max){
      //   alert('最多只能启用8个模块');
      //   return;
      // }
      // ajaxPost("/biz/json/appModule_enable.htm",{"appId":appId,"enable":isEnable},function(resp){
      //   location.reload();
      // });

      $.ajax({
        type: "DELETE",
        url: "/merchant/mboxes/"+appId+".js",
        data: { authenticity_token: window._token }
      })

    }

    $( document ).ready(function() {
        $("[rel='tooltip']").tooltip();

        $('.thumbnail').hover(
            function(){
                $(this).find('.caption').slideDown(200); //.fadeIn(250)
            },
            function(){
                $(this).find('.caption').slideUp(200); //.fadeOut(205)
            }
        );

        $('#portal_style_name').blur(function(){
            var title=$('#portal_style_name').val();
            if(title==""){
                alert("简称不能为空！");
                return ;
            }
            $.ajax({
                    type : "POST",
                    url:"/merchant/portal_styles/<%= @portal_style.id %>/save_name.js",
                    dateType:"json",
                    data: { name: title, authenticity_token: window._token }
              });
          });

        $('.carousel').carousel({
          interval: 3000
        })  
    });

    // save order
    function saveOrder() {
      var data = $("#list1 li").map(function() { return $(this).children().html(); }).get();
      $("input[name=list1SortOrder]").val(data.join("|"));

      var lis = jQuery("#list1 li");
      var appIds = [];
      for(var i=0;i<lis.size();i++){
        var obj = lis[i];
        var appId = jQuery(obj).attr("appid");
        //appIds = appIds + appId + ";";
        appIds.push(appId);
      }

      $.ajax({
        type: "POST",
        url: "/merchant/portal_styles/<%= @portal_style.id %>/save_order.js",
        data: { pids: appIds, authenticity_token: window._token }
      })
    };

  $("#list1").dragsort({ dragSelector: "div", dragBetween: true, dragEnd: saveOrder, placeHolderTemplate: "<li class='placeHolder'><div></div></li>" });

-->
</script>
<% end %>
